Repository navigation
Take UnitsState::clearAllUnits and computeLadderClimbPath off the /GL list (both back at 100%) - #541
Merged
Merged
Conversation
UnitsState::clearAllUnits (0x0052E7B0) reads 91.7% / 80.0% on main since sourcehold#238 put its file on the /GL list. It was at 100% from sourcehold#271 on, and its status line still says so. Off the list it reads 100.0% / 100.0% again; the .cpp is unchanged. The function calls fillMemory_ByteValue once per unit in a loop and once more for the unit layer. The original loads LowLevelMemory into ecx in front of that last call too (0x0052E80E). fillMemory.cpp is on the /GL list, so with clearAllUnits.cpp on it as well MSVC knows that the call leaves ecx alone and drops the load: one instruction less than the original. Its two callers are on the /GL list and no longer see its body. Both read as before: Constructor_UnitsState (0x0053B8B0) 100.0% / 100.0%, setupAllMapSections (0x00512100) 97.9% / 93.0%. Measured with real builds on main 0cea04d (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off and in one with it on (519 files, 529 functions each: every /GL file of main, the two functions of this branch, their callers and callee closures). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…100% with the units option off) UnitsState::computeLadderClimbPath (0x00533A10) reads 96.9% / 93.8% with OPENSHC_FUNCTION_VISIBILITY_UNITS off since sourcehold#238 put its file on the /GL list, and 100% with the option on. It was at 100% in sourcehold#378, and its status line still says so. Off the list it reads 100.0% / 100.0% in both modes; the .cpp is unchanged. The function calls copyData and then fillMemory_ByteValue. The original loads LowLevelMemory into ecx again between the two (0x00533A69). With the option on, copyData.cpp is a member of a wrapper unit and off the /GL list, so MSVC cannot see that it leaves ecx alone, and the load is there. With the option off both files were under /GL and the load went. Eight functions call it. The seven Update* functions among them are on the /GL list and no longer see its body with the option off (with it on they never did). All read 100.0% / 100.0%, as in main's full build: UpdateBurningMan, UpdateChild, UpdateDrunkard, UpdateFireEater, UpdateHunterDog, UpdateJester, UpdateMother and TribesState::applyLadderDestructionToTribeUnits. Measured with real builds on main 0cea04d (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with the option off and in one with it on (519 files, 529 functions each: every /GL file of main, the two functions of this branch, their callers and callee closures). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gynt
approved these changes
Dec 2, 2026
gynt
added a commit
to gynt/OpenSHC
that referenced
this pull request
Dec 2, 2026
…#543) UnitsState::processMeleeInitiation from 85.9% (gynt's text, on main since sourcehold#238) to the original's code. reccmp reads 99.0%: the seven lines it still shows are the same instructions with the same operand under another label (below), and the status line counts the function as 100% with a note that says so, as main's file does for 0x004D9290. quick_diff below is tools/reimplementation-helper/batch/quick_diff.py: this file compiled alone against the original's disassembly, every global address folded to one token. A ratio from 0 to 1, not a reccmp percentage. - The scan of the unit's own tile is a do loop behind its own test. The original loads `this` into edi in front of the loop's test (0x00549F4E) and uses it up to 0x0054A458. As a for loop MSVC loads it inside the loop and again behind the 24 tile tests, and keeps a zero in edi from the loop's end to the function's end (quick_diff 0.8976 -> 0.9399). - goto attack: when the unit already fought is still in reach, the original turns towards it and jumps into the code that starts the attack: the jmp at 0x0054A52B lands at 0x0054A6BA, which is also reached by falling through from 0x0054A6B9. With a flag set in the loop and tested behind it MSVC keeps `this` in ebx over the rest of the function, where the original reads it from the stack for each call and has 0x6a and 8 in edi and edx (0x0054A6C5). - goto noTarget: "nobody found on the 24 tiles" and "no enemy around" end in the same three stores and the same return, which the original has once: the je at 0x00549FCB lands at 0x0054A652, which is also reached by falling through from 0x0054A650. Written twice, both copies stay. - The three together: 0.9796, with the original's 734 instructions. Other forms, in quick_diff only: 0.9640 with one goto or with none (a flag that skips the second search, the attack nested in an if), 0.9244 with the attack written out at both places. The real build is of the form with the two goto. - _adjacentTiles[13] adds [SomeY + 1][5] in front of [SomeY + 1][6], as _adjacentTiles[17] does with [2] and [3]: with [6] first MSVC put the two loads the other way round than the original has them (0x0054A2C0). quick_diff folds global addresses and did not show it; the first real build did. What reccmp still shows: seven instructions (0x0054A20F, 0x0054A233, 0x0054A239, 0x0054A3D9, 0x0054A3DF, 0x0054A403, 0x0054A425) read directionTranslationMatrix one row above the current one, six written [SomeY][-1] to [-7] (gynt's negative columns of the current row) and one [SomeY - 1][0]. The matrix is the first member of TileMapState, so their displacement is TileMapState's address less 4 to 32. In the original TileMapState is at 0x01A93208 and MinimapViewState (0x01A31610, 400376 bytes) ends where it starts, so reccmp prints MinimapViewState+400372 for TileMapState - 4. In the DLL TileMapState's instance has other data in front of it and reccmp prints that: ViewportRenderState+1699844 (it is 1699848 bytes long) with the units option on, function-resolver objects with it off. The compiler's listing has TileMapState's symbol less 4 to 32 in all seven, and all 85 global memory operands of the function are the original's in the original's order. Any form that reads the row above ([SomeY][-1], [SomeY - 1][7]) comes to the same displacement (both were compiled), and the label comes from the DLL's data layout, so no source form changes these lines; main's build shows the same seven. The status line counts the function the way the file does for 0x004D9290 (sourcehold#510: the instance[i - 1] address label) and for 0x00405130, 0x004274F0 and 0x00429A40 (sourcehold#408). The rest is gynt's, the handwritten block included (7005c48 79.0%, 951fc13 84.5%, ff6859a 85.9%; main's status line still said 84.5%). The second search loses one level of nesting, so its lines show as changed. The bound of both searches is countof(field_0x11cf4[0]) in place of 24, the column count of the table they index: same object code. Measured with real builds on main 0cea04d (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp), of this file together with the two /GL lines of sourcehold#541: 99.0% in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS on (519 files, 529 functions), where every other function but sourcehold#541's clearAllUnits reads as in the same build of main. With the option off the same list reads 99.0% as well, the same seven lines (and 98.8% for the text before the _adjacentTiles[13] change: those seven and that one sum). Two comments and the two loop bounds changed after the builds; every section of the object file has the same bytes and relocations as before. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two
UnitsStatefunctions that read 100% until #238 (merged after both) put their files on the/GLlist. Off the list both read 100.0% / 100.0% (reccmp raw / normalised) again, withOPENSHC_FUNCTION_VISIBILITY_UNITSoff and on. No.cppchanges: the PR is two lines ofcmake/compiler-flags-gl.txt, one commit each./GLbuild didclearAllUnitsLowLevelMemoryinto ecx (0x0052E80E)computeLadderClimbPathLowLevelMemoryinto ecx after thecopyDatacall (0x00533A69)"Before" is main's reading (0cea04d). The status lines of both already say
100.0% | Reimplemented(from #271 and #378), so they stay as they are.What happens
clearAllUnitscallsfillMemory_ByteValueonce per unit in a loop and once more for the unit layer. The original loadsecxwithLowLevelMemoryin front of that last call too (0x0052E80E).fillMemory.cppis on the/GLlist; withclearAllUnits.cppon it as well, MSVC knows the call leavesecxalone and reuses it: one instruction less than the original. So the original was apparently compiled withoutfillMemory_ByteValue's body in view.computeLadderClimbPathcallscopyDataand thenfillMemory_ByteValue. The original loadsecxagain between the two (0x00533A69). With the option on it already read 100%:copyDatais then a member of a wrapper unit and off the/GLlist. With the option off both were under/GLand the load went.fillMemory.cppandcopyData.cppstay on the list: taking them off would change what every other/GLcaller offillMemory_ByteValueandcopyDatasees. These two lines touch only the two functions, their callers and their callees, and all of those are measured below.Callers
A file that leaves the list no longer shows its body to the
/GLfiles that call it. Every caller reads as before:clearAllUnits:Constructor_UnitsState(0x0053B8B0) 100.0% / 100.0% andsetupAllMapSections(0x00512100) 97.9% / 93.0%, as on main. WhatsetupAllMapSectionslacks is two loads of the same kind in its own code (0x0051229B, 0x005122C8). Its file is inTileMapState, and whether it can leave the list as well has not been measured, so this PR leaves it on.computeLadderClimbPath:UpdateBurningMan(0x0053BC20),UpdateChild(0x005477C0),UpdateDrunkard(0x00567320),UpdateFireEater(0x00549650),UpdateHunterDog(0x0056B970),UpdateJester(0x0056E190),UpdateMother(0x00546BC0) andapplyLadderDestructionToTribeUnits(0x00524E20, not on the list), all 100.0% / 100.0%.Measured
Setup: the bundled MSVC1400-SP1 against the Steam
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. All builds are on main 0cea04d. The small builds are of this branch together with the change toprocessMeleeInitiation.cppof #543 (that file calls neither function and is called by neither); the full build is of this branch alone./GLfile of main, the two functions, every caller of either and the callee closures, every file of a function-visibility group that touches them): BUILD_OK and 0 failures in both.clearAllUnitsandcomputeLadderClimbPathread 100.0% / 100.0% in both.clearAllUnits(91.7% / 80.0% there) andprocessMeleeInitiation, the second PR's function.processMeleeInitiation. Five more read differently with the build's file list, not with this change:UpdateChild,UpdateFireEaterandUpdateMotherread 100.0% / 100.0% here and in main's full build, 99.5%, 98.7% and 99.5% raw in main's small build, whose list lacked some of their callees.processEntityDamageToUnitreads 77.3% / 69.0% here and in main's full build, 71.5% / 67.9% in main's small one.UpdateCatapultBuildingreads 99.6% / 95.7% here, 99.6% / 95.5% in main's small build and 100.0% / 100.0% in main's full build: its code is unchanged, a known tie withUpdateFireBallistaBuildingthat goes either way with the build's file set.clearAllUnitsandcomputeLadderClimbPathread 100.0% / 100.0%, and against main's full build with the option off they are the only functions that read differently.Other PRs
#536, #539 and #543 are ours and open. #543 changes
processMeleeInitiation.cppand its status line only. #536 and #539 changecmake/compiler-flags-gl.txtin other lines (#536 adds six units, #539 takesisTowerTileOvercrowdedByCurrentPlayer.cppoff); this branch merges cleanly with each. #501 and #528 (TroopValueState) add lines to the same file at the end of the file as it was when they branched; they conflict with main there already, and this branch does not touch those lines.🤖 Generated with Claude Code